<?php
	/*
	 * All rights Reserved, Designed By www.youyacao.com <br>
	 * @Description:API记录 <br>
	 * @version 蜻蜓C影视追剧系统  <br>
	 * @author:成都市一颗优雅草科技有限公司  <br>
	 * 注意：使用我司开源源代码请遵循license文件的协议仅供个人非盈利使用，禁止用于其他的商业用途
	 * 需要商业用途或者定制开发等可访问songshu.youyacao.com  联系QQ:2853810243 422108995 23625059584
	 * 正版系统查询系统 zhengbancha.youyacao.com
	 */
namespace App\Models;
use Illuminate\Support\Facades\Auth;

class ApiLog extends BaseModel
{
    protected $table = 'api_log';

    protected $fillable = [
        'type',
        'user_id',
        'code',
        'msg',
        'requests',
        'datas',
        'method',
        'action',
        'ip'
    ];

    public static function addLog($type = 0, $code = 200, $msg = '', $datas = '')
    {
        $user = Auth::guard('api')->user();
        $user_id = $user ? $user->id:0;
        return self::create([
            'type'      => $type,
            'user_id'   => $user_id,
            'code'      => $code,
            'msg'       => $msg,
            'datas'     => json_encode($datas),
            'requests'  => json_encode(request()->all()),
            'method'    => request()->method(),
            'action'    => request()->path(),
            'ip'        => request()->ip()
        ]);
    }
}
